package com.eight.cloud.mybatisplus.method;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.eight.cloud.mybatisplus.annotation.enums.MpSqlMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 物理删除
 *
 * @ClassName: RealDelete
 * @Author: TXC
 * @Date: 2024-12-19 11:12
 **/
public class RealDelete extends AbstractMethod {
    public RealDelete() {
        this(MpSqlMethod.REAL_DELETE.getMethod());
    }

    /**
     * @param name 方法名
     * @since 3.5.0
     */
    public RealDelete(String name) {
        super(name);
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String sql;
        MpSqlMethod sqlMethod = MpSqlMethod.REAL_DELETE;
        sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(),
                sqlWhereEntityWrapper(true, tableInfo),
                sqlComment());
        SqlSource sqlSource = super.createSqlSource(configuration, sql, modelClass);
        return this.addDeleteMappedStatement(mapperClass, methodName, sqlSource);
    }
}
